<?php

namespace app\common\service\order\coupon_order\mobile;

use app\common\service\order\coupon_order\CouponOrderEntityInterface;
use app\model\CouponOrder;
use app\model\MobileOrder;
use app\model\MovieOrder;

class MobileSyncOrder extends MobileSyncBase implements CouponOrderEntityInterface
{

    public function syncOrder()
    {

        /**
         * @var CouponOrder $couponOrder
         */
        $couponOrder = $this->saveOrder();


        $changeStatusArr = [
            'status',
            'agent_settle_status',
            'refund_status',
            'profit',
            'platform_profit',
            'supplier_price',
            'pay_time',
        ];

        foreach ($changeStatusArr as $value) {
            if ($this->{$value} != $couponOrder->{$value}) {
                $couponOrder->{$value} = $this->{$value};
                $couponOrder->log .= date('m-d H:i:s') . $couponOrder->{$value} . '=>' > $this->{$value};
                $couponOrder->save();
            }
        }


    }

    public function getServType()
    {
        return PRODUCT_MOBILE_CPS_SERV;
    }

    public function getProductName()
    {
        return '话费';
    }

    public function getProductImage()
    {
        return 'https://s1.ax1x.com/2022/08/30/vhxatJ.png';
    }

    public function getAgentSettleStatus()
    {

        $settle_status = $this->params['settle_status'];

        if (in_array($settle_status, [
            MobileOrder::SETTLE_STATUS_NO,
            MobileOrder::SETTLE_STATUS_WAIT,
        ])) {
            return CouponOrder::C_AGENT_SETTLE_STATUS_NO;
        } else {
            return CouponOrder::C_AGENT_SETTLE_STATUS_SUCCESS;
        }

    }

    public function getStatus()
    {
        $status = $this->params['supplier_status'];

        if ($status == MobileOrder::C_SUPPLIER_STATUS_SUCCESS) {

            return CouponOrder::C_STATUS_RECHARGE_SUCCESS;
        } else {
            return CouponOrder::C_STATUS_RECHARGE_FAIL;
        }
    }


}